package decorator.coffeebar;

import decorator.coffeebar.coffee.Decaf;
import decorator.coffeebar.coffee.Espresso;
import decorator.coffeebar.coffee.LongBlack;
import decorator.coffeebar.decorator.Chocolate;
import decorator.coffeebar.decorator.Milk;

/**
 * @author: zhouyang
 * @descrpition: 装饰者模式 所有的类都继承一个抽象类 他们具有相同的某类方法
 * 构造某个类时会要求传入某个装饰器
 * 然后在进行这些方法的实际输出时 会递归调用每层的包装类 类似递归的效果
 * @time: 2019-05-24 16:59
 */
public class Main {
    public static void main(String[] args) {
        AbstractDrink order;
        order = new Decaf();
        //order1 price:3.0
        //order1 desc:Decaf-3.0
        //*************************
        //order2 price:12.0
        //order2 desc:Chocolate-3.0 && Chocolate-3.0 && Milk-2.0 && LongBlack-4.0
        System.out.println("order1 price:" + order.cost());
        System.out.println("order1 desc:" + order.getDescription());
        System.out.println("*************************");
        order = new LongBlack();
        //开始包装
        order = new Milk(order);//增加装饰者 那么最后返回方法的实现就是递归调用装饰者方法
        order = new Chocolate(order);
        order = new Chocolate(order);
        System.out.println("order2 price:" + order.cost());
        System.out.println("order2 desc:" + order.getDescription());

        //并未加任何调料 只是一层
        order = new Espresso();
        System.out.println("order3 price:" + order.cost());
        System.out.println("order3 desc:" + order.getDescription());
    }
}
